import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';

import _ from 'lodash';
import moment from 'moment';

import {conf} from '../../config';

import {Backend} from '../../providers/backend';
import {Information} from './tab-information';
import {ImagePipe} from '../../pipes/pipes';

@Component({
  templateUrl: 'build/pages/tab-test/tab-test.html',
  pipes: [ImagePipe],
})
export class TabTestPage {

  static get parameters() {
    return [[NavController], [NavParams], [Backend]];
  }

  constructor(nav, params, backend) {
    this.nav = nav;
    this.params = params;
    this.backend = backend;
    this.img = 'asset/img/sa-0001.png';
    this.test1 = true;

    this.backend.dsQuery({
      entity: 'gtig$TimelineEvent',
      viewName: 'timelineEvent-list',
      query: 'select e from gtig$TimelineEvent e order by e.timeBegin',
      first: 0,
      max: conf.pageSize
    }).then((result) => {
      // console.log(result);

      let eventsByMonth = _.chain(result).each((item) => {
        let timeBegin = moment(item.timeBegin);

        item.month = timeBegin.format('MMM');
        item.dayBegin = timeBegin.format('Do');
        item.dayFinish = moment(item.timeFinish).format('Do');

        item.yearMonth = timeBegin.format('YYYYMM');
      }).groupBy('yearMonth').map((item) => {
        return { month: item[0].month, events: item };
      }).value();

      console.log(eventsByMonth);

    });

    this.backend.dsQuery({
      entity: 'gtig$AboutUs',
      viewName: '_local',
      query: 'select e from gtig$AboutUs e',
      first: 0,
      max: 10
    }).then((result) => {
      console.log(result);
    });

    this.backend.dsFind({
      e: 'gtig$AboutUs-c12deb9e-c02c-b646-d2de-67dc89135288' + '-aboutUs-view'
    }).then((result) => {
      console.log(result);
    });

  }
  toConference(){

  }
  toInformation(){
    this.nav.push(Information);
  }
  testDownload() {
    this.backend.fileDownload('http://gti.ftbj.net/d/file/Resources/rep/2016-09-27/801ac1f74ef0f1085968338ea4cd685e.pdf');
  }
}